<?php
class Admin extends Controller
{
	function Admin()
	{
		parent::Controller();
	}
	function index()
	{
		$this->load->view('login');
	}
	function check_login()
	{
		$rules['username'] = "required";
		$rules['password'] = "required";
		$this->validation->set_rules($rules);
		if ($this->validation->run() == FALSE){
			$this->load->view('admin_index');
		}
		else
		{
			//$this->load->model('checkmodel');
			$this->load->model('commonmodel');
			$user_data = $this->commonmodel->check('gaoji_adminmanager','username',$_POST['username'],'password',md5($_POST['password']));
			if(@$user_data[0]->userid){
				$this->session->set_userdata('admin_name',$_POST['username']);
				redirect('/admin/showindex','refresh');
			}
			else{
				$baseurl=site_url();
				echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
				echo "<script language='JavaScript'>alert('密码错误');window.location.href='{$baseurl}/admin/index';</script>";
				redirect('/admin/index','refresh');
			}
		}
	}
	function showindex(){
		if($this->session->userdata('admin_name')==""){
			$baseurl=site_url();
			echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
			echo "<script language='JavaScript'>alert('请登录');window.location.href='{$baseurl}/admin/index';</script>";
		}
		else{
			$this->load->view('frame');
		}

	}
	function baidu(){
		parse_str($_SERVER['QUERY_STRING'],$_GET);
		//echo $_GET['a'];
		//echo $_GET['b'];
		//$this->load->view('baidu');
	}
	function logoff(){
		$this->session->sess_destroy();
		echo "<script language='JavaScript'>alert('退出成功');</script>";
		redirect('/user/index','refresh');

	}
	function admin_logoff(){
		$this->session->sess_destroy();
		echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
		echo "<script language='JavaScript'>alert('退出成功');</script>";
		redirect('/admin/index','refresh');
	}
}

?>